package net.uman.framework.modules.search;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import net.uman.entity.IdEntity;

public class AllSearch implements Search {
	private LuceneSearch lucene;
	private MongoDbSearch mongo;
	
	public AllSearch(LuceneSearch lucene, MongoDbSearch mongo) {
		this.lucene = lucene;
		this.mongo = mongo;
	}
	
	public void closeIndex() throws IOException {
		lucene.closeIndex();
		mongo.closeIndex();
	}

	public void createIndex(String table, String id, FieldDesc[] flds)
			throws IOException {
		lucene.createIndex(table, id, flds);
		mongo.createIndex(table, id, flds);
	}

	public void deleteIndex(IdEntity obj) throws IOException {
		lucene.deleteIndex(obj);
		mongo.deleteIndex(obj);
	}

	public void deleteIndex(String table, String id) throws IOException {
		lucene.deleteIndex(table, id);
		mongo.deleteIndex(table, id);
	}

	public void deleteIndex(String table, Criteria criteria) throws IOException {
		lucene.deleteIndex(table, criteria);
		mongo.deleteIndex(table, criteria);
	}

	public List<List<FieldDesc>> queryDate(String table, Criteria criteria)
			throws IOException {
		List<List<FieldDesc>> result = lucene.queryDate(table, criteria); 
		if (result == null || result.size() == 0) {
			result = mongo.queryDate(table, criteria);
		}
		return result;
	}

	public void clear(String table) {
		lucene.clear(table);
		mongo.clear(table);
	}
}
